<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
%>
<a href="javascript:history.back();" class="modern-back-button">
    <svg class="back-icon" viewBox="0 0 24 24">
        <path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"></path>
    </svg>
    返回
</a>
<!-- 主题切换按钮 -->
<button onclick="toggleTheme()" class="theme-toggle" style="
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 10px 15px;
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
">
    🌙/☀️
</button>
<div class="form-container">
    <form action="editGrade" method="post">
        <input type="hidden" name="gradeId" value="${gradeId}">
        <div class="form-group">
            <label>学号：</label>
            <input type="text" name="studentId" value="${studentId}" readonly>
        </div>

        <div class="form-group">
            <label>课程ID：</label>
            <input type="text" name="courseId" value="${courseId}" readonly>
        </div>

        <div class="form-group">
            <label>平时成绩：</label>
            <input type="number" value="${grade.dailyScore}" name="dailyScore" min="0" max="100" step="0.1" required>
        </div>

        <div class="form-group">
            <label>阶段成绩：</label>
            <input type="number" value="${grade.stageScore}"  name="stageScore" min="0" max="100" step="0.1" required>
        </div>

        <div class="form-group">
            <label>期末成绩：</label>
            <input type="number" value="${grade.finalScore}"  name="finalScore" min="0" max="100" step="0.1" required>
        </div>

        <div class="button-group">
        <button type="submit">提交成绩</button>
        </div>
    </form>
</div>


<script>
    document.querySelector('form').addEventListener('submit', function(e) {
        let isValid = true;

        document.querySelectorAll('input[required]').forEach(input => {
            if (!input.checkValidity()) {
                isValid = false;
                input.parentElement.classList.add('invalid');
            }
        });

        if (!isValid) {
            e.preventDefault();
            document.querySelector('.error-message').style.display = 'block';
        }
    });
        // 初始化主题
        function initTheme() {
        const savedTheme = localStorage.getItem('theme') || 'dark';
        const isLight = savedTheme === 'light';
        document.body.classList.toggle('light-mode', isLight);
        document.querySelector('.theme-toggle').textContent = isLight ? '☀️' : '🌙';
    }

        // 切换主题
        function toggleTheme() {
        const body = document.body;
        const isLight = !body.classList.contains('light-mode');
        body.classList.toggle('light-mode');
        localStorage.setItem('theme', isLight ? 'light' : 'dark');
        document.querySelector('.theme-toggle').textContent = isLight ? '☀️' : '🌙';
    }

        // 页面加载时初始化
        window.addEventListener('load', initTheme);
</script>

<link href="./css/rDBEditGradeForm.css" rel="stylesheet" />